package com.se.domain.vo;

import com.se.enums.ResultCode;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class ResultVO<T> {
    private Boolean ok = true;
    private Integer code = ResultCode.OK.getCode();
    private String msg = ResultCode.OK.getMsg();
    private T data;

    public static <T> ResultVO<T> ok(T data){
        return new ResultVO<T>(data);
    }
    private ResultVO(T data){
        this.data = data;
    }
    private ResultVO(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }
    public static ResultVO<Object> fail(Integer code, String msg){
        ResultVO<Object> vo = new ResultVO<>(code, msg);
        vo.ok = false;
        return vo;
    }
    public static ResultVO<Object> fail(ResultCode result){
        return ResultVO.fail(result.getCode(), result.getMsg());
    }
}
